package com.mofeng.myshop.domain.vo;

import com.mofeng.myshop.domain.po.CommodityCategory;
import com.mofeng.myshop.domain.po.Project;
import com.mofeng.myshop.domain.vo.base.BaseVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class CommodityCategoryVo extends BaseVo {
    @Schema(description = "项目ID")
    private String projectId;
    private String projectName;

    @Schema(description = "父级目录ID")
    private String parentId;

    private String parentName;

    @Schema(description = "图片路径")
    private String image;

    @Schema(description = "单位")
    private String unit;

    @Schema(description = "小图标")
    private String iconImage;

    @Schema(description = "按组发货，一组多少个")
    private Integer groupNumber;

    @Schema(description = "等级限制")
    private Integer levelTop;

    @Schema(description = "有无蓝图 0有 1无")
    private String hasPic;

    @Schema(description = "有无质量 0有 1无")
    private String hasMultiplier;

    @Schema(description = "虚拟删除状态， 0 存在  1删除")
    private String delete;

    @Schema(description = "是否展示 0 展示 1 不展示 注意，不展示意思是前端将不会显示此分类")
    private String show;

    @Schema(description = "是否打开 0打开 1 关闭  注意，关闭意思是无法访问，但会显示禁止访问提示")
    private String open;

    @Schema(description= "代码前缀(功能码)")
    private String codePrefix;

    public CommodityCategoryVo(CommodityCategory commodityCategory) {
        super(commodityCategory);
        this.delete = commodityCategory.getDelete();
        this.show = commodityCategory.getShow();
        this.open = commodityCategory.getOpen();
        this.unit = commodityCategory.getUnit();
        this.iconImage = commodityCategory.getIconImage();
        this.groupNumber = commodityCategory.getGroupNumber();
        this.image = commodityCategory.getImage();
        this.hasPic = commodityCategory.getHasPic();
        this.hasMultiplier = commodityCategory.getHasMultiplier();
        this.codePrefix = commodityCategory.getCodePrefix();
        this.projectId = commodityCategory.getProjectId() == null ? "" : commodityCategory.getProjectId().toString();
        Project project = commodityCategory.getProject();
        if (project != null) {
            this.projectName = project.getName();
        }
    }

    public static List<CommodityCategoryVo> change(Collection<CommodityCategory> categories) {
        if (categories == null) {
            return null;
        } else {
            return categories.stream().map(CommodityCategoryVo::new).collect(Collectors.toList());
        }
    }
}
